]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool: Add bash completion
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 28 Aug 2018 02:38:23 +0000 (04:38 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 21 Aug 2019 16:28:02 +0000 (18:28 +0200)
Completions are clearly helpful, in particular for extension UUIDs
that are often lengthy strings containing random usernames.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234

meson.build
src/extensions-tool/completion/bash/gnome-extensions [new file with mode: 0644]
src/extensions-tool/meson.build

index e11618f037bf9b9ab05b610a6c4993f971f2b67b..2bd67399d7aea5eebd2c5508578abf97671ca0b7 100644 (file)
@@ -132,6 +132,8 @@ else
   have_systemd = false
 endif
 
+bash_completion = dependency('bash-completion', required: false)
+
 if get_option('man')
   xsltproc = find_program('xsltproc')
 
diff --git a/src/extensions-tool/completion/bash/gnome-extensions b/src/extensions-tool/completion/bash/gnome-extensions
new file mode 100644 (file)
index 0000000..e028672
--- /dev/null
@@ -0,0 +1,51 @@
+
+# Check for bash
+[ -z "$BASH_VERSION" ] && return
+
+################################################################################
+
+__gnome_extensions() {
+  local commands="version enable disable info list create"
+  local COMMAND=${COMP_WORDS[1]}
+
+  _init_completion -s || return
+
+  case "${COMP_CWORD}" in
+    1)
+      COMPREPLY=($(compgen -W "help $commands" -- "$2"))
+      return 0
+      ;;
+
+    2)
+      case "$COMMAND" in
+        help)
+          COMPREPLY=($(compgen -W "$commands" -- "$2"))
+          return 0
+          ;;
+
+        disable)
+          local list_opt=--enabled
+          ;;&
+        enable)
+          local list_opt=--disabled
+          ;;&
+        enable|disable|info)
+          COMPREPLY=($(compgen -W "`gnome-extensions list $list_opt`" -- "$2"))
+          return 0
+          ;;
+      esac
+      ;;
+  esac
+
+  # Stop if we are currently waiting for an option value
+  $split && return
+
+  # Otherwise, get the supported options for ${COMMAND} (if any)
+  COMPREPLY=($(compgen -W "$(_parse_help $1 "help $COMMAND")" -- "$2"))
+  [[ $COMPREPLY == *= ]] && compopt -o nospace
+  return 0
+}
+
+################################################################################
+
+complete -F __gnome_extensions gnome-extensions
index 8e8f818cb8edc3489765bb96fb753627e603b21e..edd445a5e2ab3b90af9c905a3f2c3dc1501a9d72 100644 (file)
@@ -26,3 +26,9 @@ executable('gnome-extensions',
   dependencies: [gio_dep, gio_unix_dep],
   install: true
 )
+
+if bash_completion.found()
+  install_data('completion/bash/gnome-extensions',
+    install_dir: bash_completion.get_pkgconfig_variable('completionsdir')
+  )
+endif